package com.jeff.tianti.controller.channel;

import com.jeff.tianti.cms.dto.AssociationQueryDTO;
import com.jeff.tianti.cms.entity.Association;
import com.jeff.tianti.cms.service.AssociationService;
import com.jeff.tianti.common.dto.AjaxResult;
import com.jeff.tianti.common.entity.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * @author NOW_GO
 * @desc AssociationController
 * @date 2019-07-12
 */
@RestController
@RequestMapping("/channel/association")
@CrossOrigin(maxAge = 3600)
public class AssociationController {

    @Autowired
    private AssociationService associationService;

    @RequestMapping(value = "/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public AjaxResult list(@RequestBody AssociationQueryDTO associationQueryDTO) {
        Integer pageSize = associationQueryDTO.getPageSize();
        Integer currentPage = associationQueryDTO.getCurrentPage();
        if (pageSize == null) {
            associationQueryDTO.setPageSize(3);
        }
        if (currentPage == null) {
            associationQueryDTO.setCurrentPage(1);
        }
        PageModel<Association> page = this.associationService.queryAssociationPage(associationQueryDTO);
        return AjaxResult.setSuccessPageModelDate(page);
    }


}